var dot0 = new Image();
dot0.src = "dot-off.png";
var dot1 = new Image();
dot1.src = "dot-on.png";
var box0 = new Image();
box0.src = "box-off.png";
var box1 = new Image();
box1.src = "box-on.png";

function dtoggle(i) { i.src = i.src == dot1.src ? dot0.src : dot1.src; }

function btoggle(i) { i.src = i.src == box1.src ? box0.src : box1.src; }

function popup(mylink, windowname) {
  var href;
  if (! window.focus) { return true; }
  if (typeof(mylink) == 'string') { href=mylink; }
  else { href=mylink.href; }
  window.open(href, windowname, 'scrollbars=yes');
  return false;
}

$(document).ready(function(){
  var showText = "Show";
  var hideText = "Hide";
  var isShown = false;

  $(".showhide").click(function () {
    $(this).parent().next().toggleClass("hide");
    $(this).parent().next().next().toggleClass("hide");
    isShown = $(this).parent().next().hasClass("hide");
    $(this).html((!isShown)?hideText:showText);
  });

  $(".top").click(function () {
    $(this).parent().prev().toggleClass("hide");
    $(this).parent().toggleClass("hide");
    $(this).parent().prev().prev().children(".showhide").html("Show");
  });

  $("a.spec").click(function(event){
    event.preventDefault();
  });

  $(".roller").click(function () {
    numDice = document.getElementById("dicenum").value;
    diff = document.getElementById("diffnum").value;
    pop = document.getElementById("popnum").value;
    numSides = document.getElementById("sides").value;

    document.getElementById("resultframe").src="/cgi-bin/odice.cgi?d="+numDice+"&t="+diff+"&p="+pop;
  });

});